package com.soft.javase.ch10.test.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author wangzhisen
 * @Desc TODO
 * @date 2025/5/7
 * 6. 获取员工工资最高的人
 */
public class HighestPaidEmployee {
    public static void main(String[] args) {
        List<Employee> employees = new ArrayList<>();
        employees.add(new Employee("张三", 25, 7500));
        employees.add(new Employee("李四", 30, 8500));
        employees.add(new Employee("王五", 28, 9000));
        employees.add(new Employee("赵六", 35, 7800));

        Optional<Employee> highestPaid = employees.stream()
                .reduce((e1, e2) -> e1.getSalary() > e2.getSalary() ? e1 : e2);

        highestPaid.ifPresent(e ->
                System.out.println("工资最高的员工: " + e.getName() + ", 工资: " + e.getSalary()));
    }
}